package com.example.everying.framework.websocket.handler;/*
 * 项目名称: everything
 * 文件名: NoticeUnreadStatusMessageHandler
 * 作者: 张泽阳
 * 日期: 2025/6/27
 * 描述:
 */

import com.alibaba.fastjson2.JSONObject;
import com.example.everying.framework.websocket.service.WebSocketChatService;
import com.example.everying.model.vo.user.UserInfoVo;
import com.example.everying.service.user.UserService;
import jakarta.websocket.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class NoticeUnreadStatusMessageHandler implements MessageHandler {

    private static UserService userService;

    @Autowired
    public void setService(UserService userService) {
        NoticeUnreadStatusMessageHandler.userService = userService;
    }

    /**
     * @param session
     * @param message
     */
    @Override
    public void handle(Session session, JSONObject message) {
//        return;
        String userId = WebSocketChatService.getUserId(session);
        UserInfoVo user = userService.getUserById(userId);
        JSONObject  result = new JSONObject();
        result.put("type", "noticeUnreadStatus");
        result.put("noticeUnreadStatus", user.getNoticeUnreadCount());
        WebSocketChatService.sendMessageToUserId(userId, result.toJSONString());
//        result.put("noticeNum", sysNotificationService.count(new QueryWrapper<SysNotification>().eq("recipient_id", userId).eq("msg_status", "2")));
//        WebSocketChatService.sendMessageToUserId(userId, result.toJSONString());

    }
}
